var User = require("../../../class/user/user.c");
var _User = new User();
module.exports = {
    prefix: "/user/",
    post: {
        "login": {
            des: {
                name: "userLogin",
                content: "用户登陆",
                params: [{
                    key: "username",
                    type: "string"
                }, {
                    key: "password",
                    type: "string"
                }]
            },
            method: function*(next) {
                var self = this;
                print("用户登陆");
                try {
                    var data = yield parse(self.request);
                    var _u = yield _User.login(data);
                    self.session.user = _u;
                    console.log(_u);
                    self.body = _u;
                    console.log(self.headers)
                } catch (e) {
                    self.body = printError(e);
                };
            }
        },
        "loginer": {
            des: {
                name: "getUserLoginer",
                content: "获取已登陆用户",
                params: []
            },
            method: function*() {
                var self = this;
                console.log(self.headers)
                if (!self.session.user) {
                    self.body = printError("用户登陆超时或已退出登陆");
                    return;
                };
                self.body = self.session.user;
                print("获取已登陆用户");
            }
        },
        "loginout": {
            des: {
                name: "userLoginOut",
                content: "用户退出登陆"
            },
            method: function*(next) {
                print("用户退出登陆");
                var self = this;
                self.session.user = "";
                self.body = {};
                yield next;
            }
        }
    },
    get: {
        "info/:_id": {
            des: {
                name: "getUserInfo",
                content: "获取用户信息",
                params: [{
                    params: "_id",
                    type: "string"
                }]
            },
            method: function*() {
                var self = this;
                print("获取用户信息");
                try {
                    var _id = self.params._id;
                    var _info = yield _User.info(_id);
                    self.body = _info;
                } catch (e) {
                    console.log(e);
                    self.body = printError(e);
                };
            }
        }
    }
}
